package pta0401;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
public class Main {
	 public static List<String> convertStringToList(String line) {
		   List<String> strList = new ArrayList<String>();
		   Scanner sc = new Scanner(line);
		   while(sc.hasNext()){
			    strList.add(sc.next());
			}
			sc.close();
			return strList;
	    }
		
		
	public static void remove(List<String> list, String str){
			for (int i = list.size()-1;  i >=0; i--) {
				if(list.get(i).equals(str)){
					list.remove(i);
				}
		    }
	    }
		public static List<String> convertStringToList(String line) {
		    List<String> strList = new ArrayList<String>();
			Scanner sc = new Scanner(line);
			while(sc.hasNext()){
				strList.add(sc.next());
			}
			sc.close();
			return strList;
	}


	public static void remove(List<String> list, String str){
		for (int i = list.size()-1;  i >=0; i--) {
			if(list.get(i).equals(str)){
				list.remove(i);
			}
	    }
	}
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    while(sc.hasNextLine()){
	        List<String> list = convertStringToList(sc.nextLine());
	        System.out.println(list);
	        String word = sc.nextLine();
	        remove(list,word);
	        System.out.println(list);
	    }
	    sc.close();
    }
}




